package com.vca.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vca.common.model.category.Category;
import com.vca.common.response.CourseTypeResponse;
import com.vca.common.result.CommonResult;
import com.vca.common.vo.CourseTypeVo;
import com.vca.service.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程类型表 前端控制器
 * </p>
 *
 * @author chenBing
 * @since 2022-09-19
 */
@Slf4j
@RestController("CourseTypeController")
@RequestMapping("api/front/vcaCourseType")
@Api(tags = "课程类型控制器")
public class CourseTypeController {

    @Autowired
    private CategoryService categoryService;

    /**
     * @Description:课程类型列表
     * @Author: chenBing
     * @Date: 2022/9/20
     */
    @ApiOperation(value = "课程类型列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<List<CourseTypeResponse>> list() {
        LambdaQueryWrapper<Category> lqw = new LambdaQueryWrapper<Category>()
                .eq(Category::getType, 8)
                .ne(Category::getPid, 0)
                .eq(Category::getStatus,1)
                .orderByAsc(Category::getSort);
        List<Category> categories = categoryService.list(lqw);
        List<CourseTypeResponse> courseTypeResponseList = new ArrayList<>();
        categories.forEach(c -> {
            CourseTypeResponse courseTypeResponse = new CourseTypeResponse();
            courseTypeResponse.setId(Long.valueOf(c.getId()));
            courseTypeResponse.setCourseTypeName(c.getName());
            courseTypeResponse.setStatus(c.getStatus());
            courseTypeResponse.setLabelColor(c.getLabelColor());
            courseTypeResponse.setSort(c.getSort());
            courseTypeResponse.setPid(Long.valueOf(c.getPid()));
            courseTypeResponseList.add(courseTypeResponse);
        });
        return CommonResult.success(courseTypeResponseList);
    }
}

